﻿// <copyright file="PersistentTestCase.cs" company="DinamoGest, Lda">
// Copyright © 2009 by DinamoGest, Lda.
// All Rights Reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace IS.Projecto.Test.DataAccessLayer
{
    using NDbUnit.Core;
    using NDbUnit.Core.SqlClient;
    using Spring.Testing.NUnit;

    /// <summary>
    /// Used as base test case for persistent classes
    /// Performs set-up for spring.net and ndunit frameworks
    /// </summary>
    public abstract class PersistentTestCase : AbstractTransactionalDbProviderSpringContextTests
    {
        protected string DbSchema;
        protected string DbTestData;       
        protected SqlDbUnitTest SqlDbUnitTest;
        protected bool DeleteOnTearDown { get; set; }


        protected PersistentTestCase() { PopulateProtectedVariables = true; }

        protected override void OnSetUp()
        {
            base.OnSetUp();

            SqlDbUnitTest.ReadXmlSchema(DbSchema);
            SqlDbUnitTest.ReadXml(DbTestData);
            SqlDbUnitTest.PerformDbOperation(DbOperationFlag.CleanInsertIdentity);
        }

        protected override void OnTearDown()
        {
            base.OnTearDown();

            if (DeleteOnTearDown)
                SqlDbUnitTest.PerformDbOperation(DbOperationFlag.DeleteAll);
        }

        protected override string[] ConfigLocations
        {
            get
            {
                return new[]
                           {							   
                               "assembly://IS.Projecto.DataAccessLayer/IS.Projecto.DataAccessLayer/nhibernate.cfg.xml",
                               "assembly://IS.Projecto.DataAccessLayer/IS.Projecto.DataAccessLayer/DaoObjects.xml",
                               "assembly://IS.Projecto.Test.DataAccessLayer/IS.Projecto.Test.DataAccessLayer/ndbunit.xml"
                           };
            }
        }
    }
}